package com.tools.cleanmaster.ui.utils;

import android.content.Context;
import android.support.annotation.Nullable;

import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.OnCompositionLoadedListener;
import com.tools.cleanmaster.CleanConstant;

/**
 * Created by ChenLi on 2018/1/11.
 */

public class LottieAnimationUtil {

    /**
     * 载入动画
     *
     * @param view
     * @param name
     */
    public static void loadLottieAnimation(Context context, final LottieAnimationView view, String name, final boolean autoPlay) {
        view.setImageAssetsFolder(CleanConstant.ANIM_IMAGE_PATH + name);
        LottieComposition.Factory.fromAssetFileName(context, CleanConstant.ANIM_PATH + name + ".json", new OnCompositionLoadedListener() {
            @Override
            public void onCompositionLoaded(@Nullable LottieComposition composition) {
                if (composition != null) {
                    view.setComposition(composition);
                    if (autoPlay) {
                        view.playAnimation();
                    } else {
                        view.pauseAnimation();
                    }
                }
            }
        });
    }

}
